home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / icu-1.3.1 / icu-bin / include / uchriter.h < prev    next >
C/C++ Source or Header  |  2000-02-23  |  5KB  |  148 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998-1999      *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. */
  12.  
  13. #ifndef UCHRITER_H
  14. #define UCHRITER_H
  15.  
  16. #include "utypes.h"
  17. #include "chariter.h"
  18.  
  19.  
  20. /**
  21.  * A concrete subclass of CharacterIterator that iterates over the
  22.  * characters in a UnicodeString.  It's possible not only to create an
  23.  * iterator that iterates over an entire UnicodeString, but also to
  24.  * create only that iterates over only a subrange of a UnicodeString
  25.  * (iterators over different subranges of the same UnicodeString don't
  26.  * compare equal).  */
  27. class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
  28. public:
  29.   /**
  30.    * Create an iterator over the UnicodeString referred to by "text".
  31.    * The iteration range is the whole string, and the starting
  32.    * position is 0.  */
  33.   UCharCharacterIterator(const UChar* text, int32_t len);
  34.  
  35.   /**
  36.    * Copy constructor.  The new iterator iterates over the same range
  37.    * of the same string as "that", and its initial position is the
  38.    * same as "that"'s current position.  */
  39.   UCharCharacterIterator(const UCharCharacterIterator&  that);
  40.  
  41.   /**
  42.    * Destructor. */
  43.   ~UCharCharacterIterator();
  44.  
  45.   /**
  46.    * Assignment operator.  *this is altered to iterate over the sane
  47.    * range of the same string as "that", and refers to the same
  48.    * character within that string as "that" does.  */
  49.   UCharCharacterIterator&
  50.   operator=(const UCharCharacterIterator&    that);
  51.  
  52.   /**
  53.    * Returns true if the iterators iterate over the same range of the
  54.    * same string and are pointing at the same character.  */
  55.   virtual bool_t          operator==(const CharacterIterator& that) const;
  56.  
  57.   /**
  58.    * Generates a hash code for this iterator.  */
  59.   virtual int32_t         hashCode(void) const;
  60.  
  61.   /**
  62.    * Returns a new StringCharacterIterator referring to the same
  63.    * character in the same range of the same string as this one.  The
  64.    * caller must delete the new iterator.  */
  65.   virtual CharacterIterator* clone(void) const;
  66.                                 
  67.   /**
  68.    * Sets the iterator to refer to the first character in its
  69.    * iteration range, and returns that character, */
  70.   virtual UChar         first(void);
  71.  
  72.   /**
  73.    * Sets the iterator to refer to the last character in its iteration
  74.    * range, and returns that character.  */
  75.   virtual UChar         last(void);
  76.  
  77.   /**
  78.    * Sets the iterator to refer to the "position"-th character in the
  79.    * UnicodeString the iterator refers to, and returns that character.
  80.    * If the index is outside the iterator's iteration range, the
  81.    * behavior of the iterator is undefined.  */
  82.   virtual UChar         setIndex(UTextOffset pos);
  83.  
  84.   /**
  85.    * Returns the character the iterator currently refers to.  */
  86.   virtual UChar         current(void) const;
  87.  
  88.   /**
  89.    * Advances to the next character in the iteration range (toward
  90.    * last()), and returns that character.  If there are no more
  91.    * characters to return, returns DONE.  */
  92.   virtual UChar         next(void);
  93.  
  94.   /**
  95.    * Advances to the previous character in the iteration rance (toward
  96.    * first()), and returns that character.  If there are no more
  97.    * characters to return, returns DONE.  */
  98.   virtual UChar         previous(void);
  99.  
  100.   /**
  101.    * Returns the numeric index of the first character in this
  102.    * iterator's iteration range.  */
  103.   virtual UTextOffset      startIndex(void) const;
  104.  
  105.   /**
  106.    * Returns the numeric index of the character immediately BEYOND the
  107.    * last character in this iterator's iteration range.  */
  108.   virtual UTextOffset      endIndex(void) const;
  109.  
  110.   /**
  111.    * Returns the numeric index in the underlying UnicodeString of the
  112.    * character the iterator currently refers to (i.e., the character
  113.    * returned by current()).  */
  114.   virtual UTextOffset      getIndex(void) const;
  115.  
  116.   /**
  117.    * Copies the UnicodeString under iteration into the UnicodeString
  118.    * referred to by "result".  Even if this iterator iterates across
  119.    * only a part of this string, the whole string is copied.  @param
  120.    * result Receives a copy of the text under iteration.  */
  121.   virtual void            getText(UnicodeString& result);
  122.  
  123.   /**
  124.    * Return a class ID for this object (not really public) */
  125.   virtual UClassID         getDynamicClassID(void) const 
  126.     { return getStaticClassID(); }
  127.  
  128.   /**
  129.    * Return a class ID for this class (not really public) */
  130.   static UClassID          getStaticClassID(void) 
  131.     { return (UClassID)(&fgClassID); }
  132.  
  133. private:
  134.   UCharCharacterIterator();
  135.         
  136.   const UChar*            text;
  137.   UTextOffset              pos;
  138.   UTextOffset              begin;
  139.   UTextOffset              end;
  140.  
  141.   static char             fgClassID;
  142. };
  143.  
  144. #endif
  145.  
  146.  
  147.  
  148.